import { Component, OnInit, ViewChild, ViewChildren } from '@angular/core';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ComStepAComponent } from './com-step-a/com-step-a.component';
import { ComStepBComponent } from './com-step-b/com-step-b.component';
import { ComStepCComponent } from './com-step-c/com-step-c.component';
import { ComStepDComponent } from './com-step-d/com-step-d.component';
import { ComStepEComponent } from './com-step-e/com-step-e.component';
import { PlotService } from '../plot.service';
import { TecRecomendTipComponent } from './tec-recomend-tip/tec-recomend-tip.component';
@Component({
  selector: 'app-technical-recommend',
  templateUrl: './technical-recommend.component.html',
  styleUrls: ['./technical-recommend.component.scss']
})
export class TechnicalRecommendComponent implements OnInit {

  @ViewChild('comstep01', { static: false }) comstep01: ComStepAComponent;
  @ViewChild('comstep02', { static: false }) comstep02: ComStepBComponent;
  @ViewChild('comstep03', { static: false }) comstep03: ComStepCComponent;
  @ViewChild('comstep04', { static: false }) comstep04: ComStepDComponent;
  @ViewChild('comstep05', { static: false }) comstep05: ComStepEComponent;

  resultData: any =
    {
      "eco1": "0.83",
      "eco2": "0.17",
      "env1": "0.77",
      "env2": "0.09",
      "env3": "0.20",
      "score1": "0.88",
      "score2": "0.54",
      "score3": "0.51",
      "score4": "0.42",
      "social1": "0.64",
      "social2": "0.26",
      "social3": "0.10",
      "total1": "0.05",
      "total2": "0.23",
      "total3": "0.13",
      "total4": "0.59"
    }

  public step = 0

  public selectedTecComb = []
  constructor(
    private message: NzMessageService,
    private plotService: PlotService,
    private modal: NzModalService
  ) { }

  get disableBefore() {
    return this.step < 1
  }

  get disableNext() {
    return this.step > 5
  }


  ngOnInit() {
    // this.plotService.decisionCalc()
  }

  assessment(tecs) {
    this.selectedTecComb = tecs
    this.step = 1
  }

  before() {
    this.step -= 1
  }

  getStepParams(data) {
    let result = {}
    data.forEach(element => {
      result = Object.assign(result, element.getParams())
    });
    return result
  }

  next() {

    if (this.step == 1) {
      let data: Array<any> = this.comstep01.data
      let hasSetValue = data.every(item => {
        let { v1, v2, v3, v4 } = item;
        return typeof v1 == 'number' && typeof v2 == 'number' && typeof v3 == 'number' && typeof v4 == 'number'
      })
      if (!hasSetValue) {
        this.message.warning('存在没有输入值的输入框!')
        return
      }
    }

    this.step += 1

    // 计算
    if (this.step == 6) {


      const modal = this.modal.create({
        nzTitle: '技术推荐',
        nzContent: TecRecomendTipComponent,
        nzWidth: '600px',
        nzComponentParams: {

        },
        nzOnOk: () => { },
        nzFooter: null,
      });
      // this.message.success(`绿色可持续评估推荐选用技术体系1: 阻隔管控 + 原位化学氧化/还原 + 水泥窑协同处置`,
      //   {
      //     nzDuration: 10000
      //   });
      // this.message.success(`绿色可持续评估推荐选用技术体系1: 阻隔管控 + 原位化学氧化/还原 + 水泥窑协同处置`,
      //   {
      //     nzDuration: 10000
      //   });
      // this.message.success(`绿色可持续评估推荐选用技术体系1: 阻隔管控 + 原位化学氧化/还原 + 水泥窑协同处置`,
      //   {
      //     nzDuration: 10000
      //   });

      let data1 = this.getStepParams(this.comstep01.data)
      let data2 = this.getStepParams(this.comstep02.data)
      let data3 = this.getStepParams(this.comstep03.data)
      let data4 = this.getStepParams(this.comstep04.data)
      let data5 = this.getStepParams(this.comstep05.data)

      let params = Object.assign(data1, data2, data3, data4, data5)

      this.plotService.decisionCalc(params).subscribe(res => {
        this.resultData = res;
      })
    }
  }

}
